package org.dflish.mybatis.encrypt.config;

import lombok.AllArgsConstructor;
import org.dflish.mybatis.encrypt.plugins.EnCryptInterceptor;
import org.dflish.mybatis.encrypt.properties.EnCryptProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author liangwx
 */
@AllArgsConstructor
@EnableConfigurationProperties(EnCryptProperties.class)
@ConditionalOnProperty(
        prefix = EnCryptProperties.NAME,
        name = {"enabled"},
        havingValue = "true"
)
public class MybatisEncryptAutoConfigure {

    private final EnCryptProperties enCryptProperties;

    @Bean
    public EnCryptInterceptor enCryptInterceptor() {
        return new EnCryptInterceptor(enCryptProperties);
    }
}
